package com.ygqh.baby.utils;

import com.wdt.api.response.support.Stock;

import java.math.BigDecimal;

/**
 * 〈〉
 *
 * @author guohao
 * @date 2019/2/27 18:46
 * @since 1.0.0
 */
public class WdtStockSyncUtil {

    public final static String[] WAREHOUSE_NOS = new String[]{"001", "009"};

    public static BigDecimal getRealAmount(Stock stock) {
        if (stock == null) {
            return BigDecimal.ZERO;
        }
        // real_amount（可发库存）=实际库存-预订单量-待审核量-未付款量-待发货量-锁定库存量
        return stock.getStockNum().subtract(stock.getSubscribeNum()).subtract(stock.getOrderNum()).
                subtract(stock.getUnpayNum()).subtract(stock.getSendingNum()).subtract(stock.getLockNum());
    }

    public static BigDecimal getAmount(BigDecimal realAmount) {
        //  计算后的 real_amount 大于1的情况下， real_amount *50% ，向上取整,更新 m 站的库存
        BigDecimal amount = BigDecimal.ZERO;
        if (realAmount.compareTo(BigDecimal.ONE) > 0) {
            amount = realAmount.divide(new BigDecimal(2), 0, BigDecimal.ROUND_UP);
        }
        return amount;
    }
}
